We have all been there, you have made your awesome-lib in awesome Scheme. And you are wondering will it run on other Scheme implementations? Here I will show you how to make sure it does, using compile-scheme, make and Docker.
Install the tools
First you need to install the needed tools. I will assume you are on Debian/Ubuntu, and if you are not I will assume you can translate this to your distro.
Install the needed software other than compile-scheme with:
apt install git make docker.io gauche
then install compile-scheme with
git clone https://codeberg.org/retropikzel/compile-scheme.git
cd compile-scheme
make build-gauche
make install
Creating the test file
If youre testing R6RS create file called test.sps and put this into it:
(import (rnrs))
(display "Hello")
(newline)
If youre testing R7RS create file called test.scm and put this into it:
(import (scheme base)
(scheme write))
(display "Hello")
(newline)
Creating the Makefile
Create file called Makefile and put this into it:
.PHONY: test
SCHEME=chibi
test:
COMPILE_SCHEME=${SCHEME} compile-scheme -I . -o test test.scm
./test
-I adds current directory (.) into the implementations load path. .PHONY: test, means that even when test executable exists make will run the job.
Now running:
make test
Will compile the test.scm into executable called test, and then run it. And:
make SCHEME=gauche test
will do the same on Gauche. What if you want to test on implementation that you dont have installed?
Adding docker
Create Dockerfile with this in it:
ARG SCHEME=chibi
FROM schemers/${SCHEME}:head
RUN apt-get update && apt-get install -y make gauche git ca-certificates
RUN git clone https://codeberg.org/retropikzel/compile-scheme.git --depth=1
WORKDIR /compile-scheme
RUN make build-gauche
RUN make install
WORKDIR /workdir
And add this into the Makefile:
test-docker:
docker build --build-arg SCHEME=${SCHEME} --tag=test-${SCHEME} .
docker run -v "${PWD}:/workdir" -w /workdir -t test-${SCHEME} sh -c "make SCHEME=${SCHEME} test"
Now what will happen is that docker will user given schemers/scheme docker image, build a new image with needed tools in it and then run our previous test job inside it. -v “${PWD}:/workdir” means that current directory is mounted inside the docker container, so all the needed files are there.
If you run:
make SCHEME=kawa test-docker
A docker image will be built and your code will be run inside of it with Kawa.
To see list of implementations compile-scheme supports run any of these:
compile-scheme --list-r6rs
compile-scheme --list-r7rs
compile-scheme --list-all
So to test on all R7RS implementations in docker you can run:
for scm in (compile − scheme − −list − r7rs); domakeSCHEME={scm} test-docker; done
You might want to add –quiet into the docker build commands for this one. :) And .SILENT: test test-docker, into the Makefile after .PHONY.